package com.cm.caseManagement.controller;
import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmBeforeLitigation;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmBeforeLitigationService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 诉前Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/beforeLitigation")
public class CmBeforeLitigationController extends BaseController
{
    @Autowired
    private ICmBeforeLitigationService cmBeforeLitigationService;

    /**
     * 查询诉前列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:litigation:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmBeforeLitigation cmBeforeLitigation)
    {
        startPage();
        List<CmBeforeLitigation> list = cmBeforeLitigationService.selectCmBeforeLitigationList(cmBeforeLitigation);
        return getDataTable(list);
    }

    /**
     * 导出诉前列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:litigation:export')")
    @Log(title = "诉前", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmBeforeLitigation cmBeforeLitigation)
    {
        List<CmBeforeLitigation> list = cmBeforeLitigationService.selectCmBeforeLitigationList(cmBeforeLitigation);
        ExcelUtil<CmBeforeLitigation> util = new ExcelUtil<CmBeforeLitigation>(CmBeforeLitigation.class);
        util.exportExcel(response, list, "诉前数据");
    }

    /**
     * 获取诉前详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:litigation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmBeforeLitigationService.selectCmBeforeLitigationById(id));
    }

    /**
     * 新增诉前
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:litigation:add')")
    @Log(title = "诉前", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmBeforeLitigation cmBeforeLitigation)
    {
        return toAjax(cmBeforeLitigationService.insertCmBeforeLitigation(cmBeforeLitigation));
    }

    /**
     * 修改诉前
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:litigation:edit')")
    @Log(title = "诉前", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmBeforeLitigation cmBeforeLitigation)
    {
        return toAjax(cmBeforeLitigationService.updateCmBeforeLitigation(cmBeforeLitigation));
    }

    /**
     * 删除诉前
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:litigation:remove')")
    @Log(title = "诉前", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmBeforeLitigationService.deleteCmBeforeLitigationByIds(ids));
    }
}
